package de.karlNet.sambamanager.trees;

import org.primefaces.model.DefaultTreeNode;
import org.primefaces.model.TreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import de.karlNet.sambamanager.ldapController.AbstractLdapTree;
import de.karlNet.sambamanager.ldapController.LdapMemberTree;
import de.karlNet.sambamanager.ldapController.OriginalLdapTree;
import de.karlNet.sambamanager.ldapModel.LdapGroup;
import de.karlNet.sambamanager.ldapModel.LdapObject;
import de.karlNet.sambamanager.view.beans.ManualLeafHandlingTreeNode;

@Controller
public class LdapGroupBean extends AbstractTreeBean {
	@Autowired
	private LdapMemberTree ldapMemberTree;
	@Autowired
	private OriginalLdapTree ldapTree;

	public LdapGroupBean() {
		root = new ManualLeafHandlingTreeNode(new LdapObject("example.com",
				"dc=example,dc=com"), null);
		DefaultTreeNode myRoot = new ManualLeafHandlingTreeNode(new LdapObject(
				"example.com", "dc=example,dc=com"), root);

		System.out.println("constructed");
	}

	@Override
	protected AbstractLdapTree getLdapTree() {
		return ldapMemberTree;
	}

	@Override
	public void setSelectedNode(TreeNode selectedNode) {
		this.selectedNode = (ManualLeafHandlingTreeNode) selectedNode;
		LdapObject selectedLdapObject = this.selectedNode.getLdapObject();
		if (selectedLdapObject.getOriginalDN() != null) {
			this.selectedNode.setLdapObject(this.ldapTree
					.getObject(selectedLdapObject.getOriginalDN()));
			this.informOtherBeansOfSelect();
		}
	}

}
